# Maintainer: Maxime Gauduin <alucryd@archlinux.org>

pkgname=libretro-play
pkgver=7657
pkgrel=1
pkgdesc='Sony PlayStation 2 core'
arch=(loong64 x86_64)
url=https://github.com/jpd002/Play-
license=(MIT)
groups=(libretro)
depends=(
  bzip2
  glew
  glibc
  glu
  icu
  libgl
  libretro-core-info
  zlib
)
makedepends=(
  cmake
  git
  libglvnd
)
_commit=8e1cc18be61f5baac0c78b9eeeb2f75d196217a5
source=(
  libretro-play::git+https://github.com/jpd002/Play-.git#commit=${_commit}
  play-CodeGen::git+https://github.com/jpd002/Play--CodeGen.git
  play-Dependencies::git+https://github.com/jpd002/Play-Dependencies.git
  git+https://github.com/gulrak/filesystem.git
  play-Framework::git+https://github.com/jpd002/Play--Framework.git
  play-libchdr::git+https://github.com/jpd002/libchdr.git
  play-Nuanceur::git+https://github.com/jpd002/Nuanceur.git
  git+https://github.com/SDWebImage/SDWebImage.git
  git+https://github.com/Cyan4973/xxHash.git
  git+https://github.com/facebook/zstd.git
)
b2sums=(
  SKIP
  SKIP
  SKIP
  SKIP
  SKIP
  SKIP
  SKIP
  SKIP
  SKIP
  SKIP
)

pkgver() {
  cd libretro-play
  git rev-list --count HEAD
}

prepare() {
  cd libretro-play

  git config --global protocol.file.allow always

  for submodule in deps/{CodeGen,Dependencies,Framework,Nuanceur,libchdr}; do
    git submodule init ${submodule}
    git config submodule.${submodule}.url ../play-${submodule#*/}
    git submodule update ${submodule}
  done

  cd deps/Dependencies

  git submodule init SDWebImage
  git config submodule.SDWebImage.url ../../../SDWebImage
  git submodule update SDWebImage

  git submodule init ghc_filesystem
  git config submodule.ghc_filesystem.url ../../../filesystem
  git submodule update ghc_filesystem

  git submodule init xxHash
  git config submodule.xxHash.url ../../../xxHash
  git submodule update xxHash

  git submodule init zstd
  git config submodule.zstd.url ../../../zstd
  git submodule update zstd
}

build() {
  cmake -S libretro-play -B build \
    -DCMAKE_BUILD_TYPE=Release \
    -DBUILD_LIBRETRO_CORE=ON \
    -DBUILD_PLAY=OFF \
    -DBUILD_TESTS=OFF \
    -DENABLE_AMAZON_S3=OFF \
    -Wno-dev
  make -C build
}

package() {
  install -Dm 644 build/Source/ui_libretro/play_libretro.so -t "${pkgdir}"/usr/lib/libretro/
  install -Dm 644 libretro-play/License.txt -t "${pkgdir}"/usr/share/licenses/libretro-play/
}

# vim: ts=2 sw=2 et:
